/**
 * FileName: TestImportBeanDefinitionRegistrar
 * Author:   xing.yang@vcg.com
 * Date:     2020/6/2 17:26
 * Description:
 */
package com.vcg.vdam.config;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class TestImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    //第一种普通方式
//    @Override
//    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
//        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(TestBean4.class);
//        rootBeanDefinition.getPropertyValues().add("name","yyxx");
//        registry.registerBeanDefinition("TestBean4", rootBeanDefinition);
//    }

    //第二种通过factorybean来注入
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(MyFactoryBean.class);
        rootBeanDefinition.getPropertyValues().add("name","我是facotorybean创建的test4");
        rootBeanDefinition.getPropertyValues().add("tClass",TestBean4.class);

        RootBeanDefinition rootBeanDefinition2 = new RootBeanDefinition(MyFactoryBean.class);
        rootBeanDefinition2.getPropertyValues().add("name","我是facotorybean创建的test5");
        rootBeanDefinition2.getPropertyValues().add("tClass",TestBean5.class);


        registry.registerBeanDefinition("testBean5", rootBeanDefinition2);
        registry.registerBeanDefinition("testBean4", rootBeanDefinition);
    }
}
